home *** CD-ROM | disk | FTP | other *** search
- /*
- * ProjectSwitch: FKEY that works with QuicKeys to automate project switching for multiple project
- * environments. It puts the name of the current project into a QuicKey text key.
- * This can be used as a form of parameter substitution for sequences.
- * The key chosen is Cmd-Option-Shift 1.
- */
-
-
- #include <MacTypes.h>
- #include <MemoryMgr.h>
- #include <EventMgr.h>
- #include <WindowMgr.h>
- #include <SegmentLdr.h>
- #include "QuicKeys.h"
-
- #define NULL 0L
-
- /* Forward references */
- QuicInitBlock *FindSysHeap();
- Boolean UpdateParamKey(QuicInitBlock *qb, StringHandle theText, int param);
-
- pascal void
- main()
- {
- register WindowPeek wp;
- register QuicInitBlock *qb;
-
- /* Have to be running Lightspeed C */
- if (IUCompString(CurApName, "\pLightspeedCâ„¢") != 0) {
- SysBeep(1);
- return;
- }
-
- if ((qb = FindSysHeap()) == NULL) {
- SysBeep(1);
- return;
- }
-
- /*
- * Search the window list for the project window. This search relies on Lightspeed C internals
- * deduced via TMON - namely: document windows have a windowKind of 0xB, and the project
- * window has one of 0xA.
- */
- for (wp = WindowList; wp != NULL; wp = wp->nextWindow) {
- if (wp->windowKind == 0xA) { /* A project window */
- /* wp->titleHandle is a StringHandle to the window title. This corresponds to the
- * project name. So we search for the reserved key record (type QK_TEXT,
- * key 1, modifiers (Cmd,Option,Shift). When found, we copy in the required
- * title.
- */
- if (UpdateParamKey(qb, wp->titleHandle, 1) == FALSE) SysBeep(1);
- return;
- }
- }
- }
-
-
- /*
- * This is a C version of the example code in Chapter 8 of the QuicKeys manual.
- */
-
- QuicInitBlock *
- FindSysHeap()
- {
- register Ptr endBlk = SysZone->bkLim;
- register QuicInitBlock *qp;
-
- qp = (QuicInitBlock *) &SysZone->heapData;
-
- while(qp != (QuicInitBlock *) endBlk) {
- /* Analyze the block we're looking at. */
- if ((qp->header[0] & 0xC0) == 0x40) { /* Is it non-relocatable? */
- /* Check magic and signature. */
- if (qp->quic.magic == 0xa89f1234 && qp->quic.signature == 'CELN') {
- /* Chapter 8 states that the version number is 1. It's actually 0 (as the example
- * assembly language shows and a quick call to CE Software confirmed).
- */
- if (qp->quic.version == 0) return qp;
- }
- }
-
- /* Time to move on to the next block. The 0xFFFFFF strips off the tag byte(s). */
- qp = (QuicInitBlock *)(((Byte *)qp) + ((* (long *)&qp->header) & 0xFFFFFF));
- }
- return NULL; /* Failed to find it */
- }
-
- /*
- * Cmd-Shift-Option 1 through 4 are reserved as parameter records of type 'text' (prog-specific).
- * This routine searches for the given record and copies in the text.
- */
-
- Boolean
- UpdateParamKey(qb, theText, param)
- QuicInitBlock *qb;
- StringHandle theText;
- int param;
- {
- register KeyRecord *kr = qb->quic.application;
- register KeyRecord *end = kr + N_QCKEYS;
- register unsigned key;
-
- /* This depends on the fact that keys 1 through 4 have consecutive keycode values. The charcode values
- * were found by experimentation.
- */
- key = ((0x11 + param) << 8) + 0xD9 + param; /* Convert to keycode & charcode */
-
- for (; kr < end; kr++) {
- if (kr->QKtype == QK_TEXT) {
- if ((kr->key) == key && (kr->modifiers == (cmdKey|optionKey|shiftKey))) {
- BlockMove(*theText, kr->u.QuicText.text, (Size)((*theText)[0] + 1));
- return TRUE;
- }
- }
- }
- return FALSE;
- }
-